package logic

import (
	"context"
	"shuqi_novel/shop_rpc/shop_rpc"

	"shuqi_novel/api/internal/svc"
	"shuqi_novel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookUpdataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookUpdataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookUpdataLogic {
	return &BookUpdataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookUpdataLogic) BookUpdata(req *types.BookUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.ShopRpc.BookUpdate(l.ctx, &shop_rpc.BookUpdateRequest{
		AuthorId: int64(req.AuthorId),
		BookId:   int64(req.BookId),
		Title:    req.Title,
		Image:    req.Image,
		Type:     req.Type,
		Des:      req.Des,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "小说修修改成功",
		Data:    update,
	}, nil
}
